package com.bwie.spu.controller;

import java.util.List;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bwie.spu.domain.dto.ProductUpDTO;
import com.bwie.spu.domain.vo.ProductVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bwie.common.security.annotation.RequiresPermissions;
import com.bwie.spu.domain.po.ProductPo;
import com.bwie.spu.service.IPmsSpuInfoService;
import com.bwie.common.core.web.controller.BaseController;
import com.bwie.common.core.web.domain.AjaxResult;
import com.bwie.common.core.utils.poi.ExcelUtil;
import com.bwie.common.core.web.page.TableDataInfo;

/**
 * spu信息Controller
 *
 * @author bwie
 * @date 2024-12-18
 */
@RestController
@RequestMapping("/info")
public class PmsSpuInfoController extends BaseController
{
    @Autowired
    private IPmsSpuInfoService pmsSpuInfoService;

    /**
     * 查询spu信息列表
     */
    @RequiresPermissions("spu:info:list")
    @GetMapping("/list")
    public TableDataInfo list(ProductPo productPo)
    {
        startPage();
        List<ProductVo> list = pmsSpuInfoService.selectPmsSpuInfoList(productPo);
        return getDataTable(list);
    }

    /**
     * 导出spu信息列表
     */
    @RequiresPermissions("spu:info:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductPo productPo)
    {
        List<ProductVo> list = pmsSpuInfoService.selectPmsSpuInfoList(productPo);
        ExcelUtil<ProductVo> util = new ExcelUtil<ProductVo>(ProductVo.class);
        util.exportExcel(response, list, "spu信息数据");
    }

    /**
     * 获取spu信息详细信息
     */
    @RequiresPermissions("spu:info:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(pmsSpuInfoService.selectPmsSpuInfoById(id));
    }

    /**
     * 新增spu信息
     */
    @RequiresPermissions("spu:info:add")
    @PostMapping
    public AjaxResult add(@RequestBody ProductPo productPo)
    {
        return toAjax(pmsSpuInfoService.insertPmsSpuInfo(productPo));
    }

    /**
     * 修改spu信息
     */
    @RequiresPermissions("spu:info:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody ProductPo productPo)
    {
        return toAjax(pmsSpuInfoService.updatePmsSpuInfo(productPo));
    }

    /**
     * 删除spu信息
     */
    @RequiresPermissions("spu:info:remove")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(pmsSpuInfoService.deletePmsSpuInfoByIds(ids));
    }

    /**
     * 上架功能
     * @param productUpDTO
     * @return
     */
    @PostMapping("up")
    public AjaxResult up(@RequestBody ProductUpDTO productUpDTO) {
    	//调用方法
        pmsSpuInfoService.productUp(productUpDTO);
        //返回
        return AjaxResult.success();
    }
}
